'''
Created on Oct 21, 2014

@author: azhelezny
'''
materityAge = 1  # 1 mounth

time = 0

class PairOfRabbits:
    def __init__(self, ttl):
        if(time == 0):
            self.creationTime = 0
        else:
            self.creationTime = time + 1 # not born yet
        self.ttl = ttl
        self.descendants = []
        self.name = "rabbit, ct :"+format(self.creationTime)+ " time: "+format(time)
        
    def multiply(self):
        for i in self.descendants:
            i.multiply()
        if(not self.isAlive() or not self.isMateur()):
            return
        self.descendants.append(PairOfRabbits(self.ttl))
        
    def isAlive(self):
        return (time - self.creationTime < self.ttl and not self.creationTime > time)
    
    def isMateur(self):
        return (time - self.creationTime >= materityAge)
    
    def getLiveRabbits(self):
        aliveRabbitsCount = 0
        if(self.isAlive()):
#            print("pish")
            aliveRabbitsCount += 1
#           print(self.name)
        for rabbit in self.descendants:
            aliveRabbitsCount += rabbit.getLiveRabbits()
        return aliveRabbitsCount
        
timeToLive = 3
durationOfObservation = 6

rabbits = PairOfRabbits(timeToLive)
for time in range (0, durationOfObservation):
    rabbits.multiply()
    print("Month : " + format(time)+ " Rabbits:" +format(rabbits.getLiveRabbits()))
#print("Answer is: " + format(rabbits.getLiveRabbits()))

    
